package spring.angularjs.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import spring.angularjs.domain.Addressbook;

@Repository
public class AddressBookDAOImpl implements AddressBookDAO {
	
	@Autowired
	private SessionFactory sessionFactory;

	@Override
	public void addAddressBook(Addressbook ab) {
		sessionFactory.getCurrentSession().save(ab);
	}

	@Override
	public void deleteAll() {
		sessionFactory.getCurrentSession().createQuery("delete from Addressbook").executeUpdate();
	}

	@Override
	public void deleteAddressBook(Addressbook ab) {
		sessionFactory.getCurrentSession().delete(ab);
	}

	@Override
	public List<Addressbook> getList() {
		return sessionFactory.getCurrentSession().createCriteria(Addressbook.class).list();
	}

	@Override
	public Addressbook getAddressbook(int idab) {
		return (Addressbook) sessionFactory.getCurrentSession().get(Addressbook.class, idab);
	}

	@Override
	public void updateAddressbook(Addressbook ab) {
		sessionFactory.getCurrentSession().update(ab);
	}

}
